import urllib.request as r
import urllib.parse as p
import http.cookiejar as c
url='http://bbs.chinaunix.net/member.php?mod=logging&action=login&loginsubmit=yes&loginhash=LxogS'
postdata=p.urlencode({
    'username':'admintest166',
    'password':'test1234'
}).encode('utf-8')
req=r.Request(url,postdata)
req.add_header('User-Agent','Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36 SE 2.X MetaSr 1.0')

cjar=c.CookieJar()
opener=r.build_opener(r.HTTPCookieProcessor(cjar))
r.install_opener(opener)

file=opener.open(req)
data=file.read()
with open('1.html','wb')as p:
    print('data是什么类型的:',type(data))
    p.write(data)
    print('1.html爬取完毕')

url2='http://bbs.chinaunix.net/'
data2=r.urlopen(url2).read()
with open('2.html','wb')as b:
    b.write(data2)
    print('2.html爬取完毕')